package com.yidu.t299.dao.ljc;
import com.yidu.t299.domain.ljc.Material;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * @author 刘建常
 * @version 1.0
 * @description
 * @date:2023/3/7 11:35
 */
@Mapper
public interface MaterialMapper {
    /**
     * 根据书籍编号删除该书籍信息
     * @param stockId 书籍编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({
            "delete from textbook_stock" +
                    " where stock_id = #{stockId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer stockId);

    /**
     * 添加书籍信息
     * @param record 书籍对象
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({
            "insert into textbook_stock (stock_id, textbook_name,textbook_num,textbook_author,textbook_price)" +
                    " values (#{stockId,jdbcType=INTEGER}, #{textbookName,jdbcType=VARCHAR}," +
                    "#{textbookNum,jdbcType=INTEGER},#{textbookAuthor,jdbcType=VARCHAR}," +
                    "#{textbookPrice,jdbcType=VARCHAR})"
    })
    int insert(Material record);

    /**
     * 根据书籍编号查询指定的信息
     * @param stockId 书籍编号
     * @return 书籍对象
     */
    @Select({
            "select" +
                    " stock_id, textbook_name,textbook_num,textbook_author,textbook_price" +
                    " from textbook_stock" +
                    " where stock_id = #{stockId,jdbcType=INTEGER}"
    })
    @Results(id = "MaterialMap",value = {
            @Result(id = true,column = "stock_id",property = "stockId"),
            @Result(column = "textbook_name",property = "textbookName"),
            @Result(column = "textbook_num",property = "textbookNum"),
            @Result(column = "textbook_author",property = "textbookAuthor"),
            @Result(column = "textbook_price",property = "textbookPrice")
    })
    Material selectByPrimaryKey(Integer stockId);

    /**
     * 按条件分页查询校区数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 校区对象集合
     */
    @Select("select * from textbook_stock where 1=1 ${condition} limit #{page},#{rows}")
    @ResultMap("MaterialMap")
    List<Material> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);


    /**
     * 按条件查询material表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from textbook_stock where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 根据书籍信息修改其数据
     * @param record 书籍对象
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
            "update textbook_stock"+
            " set textbook_name = #{textbookName,jdbcType=VARCHAR},"+
            " textbook_num = #{textbookNum,jdbcType=INTEGER},"+
            " textbook_author = #{textbookAuthor,jdbcType=VARCHAR},"+
            " textbook_price = #{textbookPrice,jdbcType=VARCHAR}"+
            " where stock_id = #{stockId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Material record);
}
